#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>

using namespace std;

class Solution {
public:
    int maxConsecutiveAnswers(string answerKey, int k) {
        /* 滑动窗口，两次遍历 */
        int maxLen = 0;
        SliceWindow(answerKey, maxLen, 'F', k);
        SliceWindow(answerKey, maxLen, 'T', k);

        return maxLen;
    }

    void SliceWindow(const string& answerKey, int& maxLen, char ch, int k)
    {
        int answerKeyLen = answerKey.length();
        int left = 0; 
        int right = 0;
        int count = 0;

        while (right < answerKeyLen) {
            if (answerKey[right] == ch) {
                count++;
            }

            while (count > k) {
                /* 左滑 */
                if (answerKey[left] == ch) {
                    count--;
                }
                left++;
            }

            maxLen = max(right - left + 1, maxLen);

            right++;
        }
    }
};  


int main()
{   
    Solution s;
    cout << s.maxConsecutiveAnswers("TTFTTFTT", 1) << endl;
    return 0;
}